package com.geek.novel.vo

import com.geek.novel.utils.GsonUtil
import com.geek.novel.utils.ToastUtils
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.reflect.TypeToken
import java.util.*
import kotlin.collections.ArrayList

/**
 * 请求数据返回
 * @author Hydra
 */
class ApiResult {
    var result: Any? = null
    var resultList: JsonArray? = null
    var isResult: Boolean = false
    var content: String = ""
    var code: Int = 0
    var params: Map<String, Any>? = null

    fun getData(): Any?{
        return this.result
    }
    fun <T> getList(cls: Class<T>): List<T>{
        if(this.resultList == null){
            ToastUtils.toast("获取列表结果为空！请标记请求类型为：Constant.HTTP_RESULT_TYPE_LIST")
            return ArrayList()
        }
        return GsonUtil.fromJsonList(this.resultList!!, cls)
    }
}
